package com.mgface.framework.servlet;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;

@Configuration
public class ServletConfiguration {
	@Value("${system.name:mgface}")
	private String projectName;

	@Bean
	public ServletRegistrationBean servletRegistrationBean() {
		ServletRegistrationBean sr = new ServletRegistrationBean(new SBDServlet(), "/sbdservlet");
		sr.setAsyncSupported(true);
		sr.setLoadOnStartup(-1);
		return sr;
	}

	/**
	 * 自定义dispatcherServlet的映射关系,覆盖默认值
	 * 
	 * @param dispatcherServlet
	 * @return
	 */
	@Bean
	public ServletRegistrationBean dispatcherRegistration(DispatcherServlet dispatcherServlet) {
		ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet);
		registration.addUrlMappings("/" + this.projectName + "/*");
		return registration;
	}
}
